package xxhui.space.newsclient;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import xxhui.space.newsclient.Adapter.UserDetatlRecyclerViewAdapter;
import xxhui.space.newsclient.Bean.HeadlineItem;

public class UserDetailActivity extends AppCompatActivity {

    @BindView(R.id.user_detail_toolbar)
    Toolbar toolbar;
    @BindView(R.id.user_detail_list)
    RecyclerView recyclerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_detail);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {

        setSupportActionBar(toolbar);
        ActionBar actionBar =  getSupportActionBar();
        if(actionBar != null) {
            //取消默认标题，并显示返回按钮
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        recyclerView.setItemAnimator(new DefaultItemAnimator());

        //加载RecycleView的数据
        UserDetatlRecyclerViewAdapter adapter = new UserDetatlRecyclerViewAdapter(getData());
        recyclerView.setAdapter(adapter);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        //点击back键finish当前activity
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return true;
    }

    public List<HeadlineItem> getData(){
        List<HeadlineItem> list = new ArrayList<HeadlineItem>();
        for(int i=0 ; i<15 ;i++){
            list.add(new HeadlineItem("","用户名","仅仅7天，3万把共享雨伞全军覆没！不盈利真当做公益了？",
                    "全国暴雨季如期而至，街上的同享单车全都惨兮兮地淋在雨里，骑行人次显着削减。但这让人想起别的一个刚刚鼓起不久的项目——同享雨伞。风口等了这么久，总算轮到它上场了。123456789",""));
        }
        return list;
    }


}
